<?php $row = $cliente->row();?>
<?php $raw = $compra->row();?>
<html>
<head>
    <title>Confirmaci&oacute;n de su pedido</title>
    <style type="text/css">
        <!--
        .Stil1 {
            font-family: Verdana, Arial, Helvetica, sans-serif;
            font-size: 12px;
        }
        .Stil2 {
            font-family: Verdana, Arial, Helvetica, sans-serif
        }
        -->
    </style>
</head>
<body>
    <table width="100%" align="center" border="0" cellspacing="0" cellpadding="2" summary="">
        <tr valign="top">
            <td width="10" rowspan="2"></td>
            <td bgcolor="#CCCCCC" align="left" class="Stil1" colspan="2">
                <h3 class="Stil2">Mercado Encantado</h3>
                Beiro 4640 4to C (B1678CQR) Villa Devoto<br>
                Tel: (011) 4503-6849<br>
            </td>
        </tr>
        <tr bgcolor="white">
            <td colspan="2">
                <h3 class="Stil2">Informaci&oacute;n del pedido</h3>
            </td>
        </tr>
    </table>
    <table border="0" cellspacing="0" cellpadding="2" width="100%" summary="">
        <!-- begin customer information -->
        <tr class="sectiontableheader">
            <td width="10" rowspan="22"></td>
            <td colspan=2 class="Stil2" bgcolor="#CCCCCC"><b>Datos del pedido</b></td>
        </tr>
        <tr class="Stil1">
            <td><strong>N&uacute;mero de pedido:</strong></td>
            <td><?=$raw->order_id?></td>
        </tr>
        <tr class="Stil1">
            <td><strong>Cliente:</strong></td>
            <td><?=$this->session->userdata('name')?>(<?=$row->username?>)</td>
        </tr>
        <tr class="Stil1">
            <td><strong>Orden de Compra:</strong></td>
            <td><?=$raw->orden_compra?></td>
        </tr>
        <tr class="Stil1">
            <td><strong>Fecha:</strong></td>
            <td><?=date("d/m/y h:m",$raw->cdate)?></td>
        </tr>
        <tr class="sectiontableheader">
            <td colspan="2">&nbsp;</td>
        </tr>
        <tr bgcolor="#CCCCCC" class="sectiontableheader">
            <td colspan="2"><b class="Stil2">Datos del cliente</b></td>
        </tr>
        <tr valign="top" class="Stil1">
            <td width="20%">
                <strong>Domicilio:</strong>
            </td>
            <td><?=$row->address_1?></td>
        </tr>
        <tr class="Stil1">
            <td><strong>Localidad:</strong></td>
            <td><?=$row->city?></td>
        </tr>
        <tr class="Stil1">
            <td><strong>Provincia:</strong></td>
            <td><?=$row->state?></td>
        </tr>
        <tr class="Stil1">
            <td><strong>Codigo Postal:</strong></td>
            <td><?=$row->zip?></td>
        </tr>
        <tr class="Stil1">
            <td><strong>Tel&eacute;fono:</strong></td>
            <td><?=$row->phone_1?></td>
        </tr>
        <tr class="Stil1">
            <td><strong>Fax:</strong></td>
            <td><?=$row->fax?></td>
        </tr>
        <tr>
            <td colspan=2>&nbsp;</td>
        </tr>
        <tr>
            <td colspan=2>&nbsp;</td>
        </tr>
        <tr>
            <td colspan=2>&nbsp;</td>
        </tr>
        <!-- begin order items information -->
        <tr bgcolor="#CCCCCC" class="Stil2">
            <td colspan="2"><b>Pedido</b></td>
        </tr>
        <tr>
            <td colspan="2">
            <table width="100%" cellspacing="0" cellpadding="2" border="0" summary="">
            <tr align="center" class="Stil1">
                <th>Cantidad</th>
                <th>Descripcion</th>
                <th>Codigo</th>
                <th>Precio</th>
                <th>Total</th>
            </tr>
            <tr align="right" class="Stil1">
                <?php
                $total_price=$i=0;$color=1;
                $query = $this->db->query("SELECT * FROM order_item WHERE order_id=".$raw->order_id);
                foreach ($query->result() as $row):
                $total_price += $row->product_quantity*$row->product_item_price;
                ?>
                <?php echo $i++%2==0 ? "<tr>" : "<tr class='odd'>"; ?>
                <td><?php echo $row->product_quantity; ?></td>
                <td><?php echo $row->order_item_name; ?></td>
                <td>$<?php echo $row->order_item_sku; ?></td>
                <td>$<?php echo $row->product_item_price; ?></td>
                <td>$<?php echo $row->product_quantity*$row->product_item_price;?></td>
            </tr>
            <?php endforeach;
            $query = $this->db->query("SELECT extra_field_1, extra_field_2, extra_field_3, extra_field_5 FROM users WHERE id=".$this->session->userdata('id'));
            if ($query->num_rows() > 0)
            $row=$query->row();

            $order_total = $total_price;
            $bonificacion = ($order_total * $row->extra_field_3) / 100;
            $bonificacion2 = ($order_total * $row->extra_field_5) / 100;
            $iva = (($order_total - $bonificacion - $bonificacion2) * $row->extra_field_1) / 100;
            $percepcion = (($order_total - $bonificacion - $bonificacion2) * $row->extra_field_2) / 100;
            $total = $order_total - $bonificacion - $bonificacion2 + $iva + $percepcion;

            if ($row->extra_field_3=="47.62"){
                $titulo="Bonificacion 1: 40%+10%+3%";
            }elseif ($row->extra_field_3=="50.239"){
                $titulo="Bonificacion 1: 40%+10%+5%+3%";
            } elseif ($row->extra_field_3=="52.858"){
                $titulo="Bonificacion 1: 40%+10%+10%+3%";
            } elseif ($row->extra_field_3=="41.80"){
                $titulo="Bonificacion 1: 40%+3%";
            } else {
                $titulo="Bonificacion 1: 3%";
            }

            ?>
        </tr>
        <tr class="Stil1">
            <td colspan="5" align="right">&nbsp;&nbsp;</td>
            <td>&nbsp;</td>
        </tr>
        <tr align=left class="Stil1">
            <td align="left"><strong>Sub Total</strong></td>
            <td align="right">$<?php echo $total_price; ?></td>
            <td colspan="3">&nbsp;</td>
        </tr>
        <tr align=left class="Stil1">
            <td align="left"><strong><?=$titulo;?></strong></td>
            <td align="right">($<?= number_format($bonificacion, 2, '.', ' ');?>)</td>
            <td colspan="3">&nbsp;</td>
        </tr>
        <tr align=left class="Stil1">
            <td align="left"><strong>IVA</strong></td>
            <td align="right">$<?= number_format($iva, 2, '.', ' ');?></td>
            <td colspan="3">&nbsp;</td>
        </tr>
        <tr align=left class="Stil1">
            <td align="left"><strong>Percepcion IBB</strong></td>
            <td align="right">$<?= number_format($percepcion, 2, '.', ' ');?></td>
            <td colspan="3">&nbsp;</td>
        </tr>
        <tr class="Stil1">
            <td align="left"><b>Total:</b></td>
            <td align="right"><b>$<?= number_format($total, 2, '.', ' ');?></b></td>
            <td colspan="3">&nbsp;</td>
        </tr>
        <tr class="Stil1">
            <td colspan="5" align="left" style="font-size : 10px;">
                <br>
            </td>
        </tr>
        <tr class="Stil1">
            <td colspan="5" align="left" style="font-size : 10px;">
            </td>
        </tr>
    </table>
    </td>
    </tr>
    <!-- end order items information -->
    <!-- begin customer note -->
    <tr class="sectiontableheader">
        <td colspan="2">&nbsp;</td>
    </tr>
    <tr bgcolor="#CCCCCC" class="sectiontableheader">
        <td colspan="2"><b class="Stil2">Mensaje del cliente:</b></td>
    </tr>
    <tr>
        <td colspan="2"><?php echo $raw->customer_note; ?></td>
    </tr>
    <tr bgcolor="#CCCCCC" class="sectiontableheader">
        <td colspan="2" class="Stil1">Gracias por su compra.</td>
    </tr>
    </table>
    <p class="Stil2">&nbsp;</p>
</body>
</html>
